<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>桶和指标的组合 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_combining_the_two.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_combining_the_two.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_combining_the_two.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_combining_the_two.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="aggregations.html">聚合</a></span>
»
<span class="breadcrumb-link"><a href="aggs-high-level.html">高阶概念</a></span>
»
<span class="breadcrumb-node">桶和指标的组合</span>
</div>
<div class="navheader">
<span class="prev">
<a href="_metrics.html">« 指标</a>
</span>
<span class="next">
<a href="_aggregation_test_drive.html">尝试聚合 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_combining_the_two"></a>桶和指标的组合 (Combining of Bucket and Metric)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/301_Aggregation_Overview.asciidoc">edit</a>
</h2>
</div></div></div>
<p><em>聚合</em> 是由桶和指标组成的。 聚合可能只有一个桶，可能只有一个指标，或者可能两个都有。也有可能有一些桶嵌套在其他桶里面。例如，我们可以通过所属国家来划分文档（桶），然后计算每个国家的平均薪酬（指标）。</p>
<p>由于桶可以被嵌套，我们可以实现非常多并且非常复杂的聚合：</p>
<p>1.通过国家划分文档（桶）</p>
<p>2.然后通过性别划分每个国家（桶）</p>
<p>3.然后通过年龄区间划分每种性别（桶）</p>
<p>4.最后，为每个年龄区间计算平均薪酬（指标）</p>
<p>最后将告诉你每个 <code class="word">&lt;国家, 性别, 年龄&gt;</code> 组合的平均薪酬。所有的这些都在一个请求内完成并且只遍历一次数据！</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="_metrics.html">« 指标</a>
</span>
<span class="next">
<a href="_aggregation_test_drive.html">尝试聚合 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>